package com.example.diaoxinlei

import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity
import com.example.diaoxinlei.ui.theme.Student

class SecondActivity : AppCompatActivity() {

    private lateinit var etId: EditText
    private lateinit var etName: EditText
    private lateinit var etGender: EditText
    private lateinit var etClass: EditText
    private lateinit var btnConfirm: Button
    private lateinit var btnCancel: Button

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_second)

        etId = findViewById(R.id.et_id)
        etName = findViewById(R.id.et_name)
        etGender = findViewById(R.id.et_gender)
        etClass = findViewById(R.id.et_class)
        btnConfirm = findViewById(R.id.btn_confirm)
        btnCancel = findViewById(R.id.btn_cancel)

        btnConfirm.setOnClickListener {
            val student = Student(etId.text.toString(), etName.text.toString(), etGender.text.toString(), etClass.text.toString())
            val intent = Intent()
            intent.putExtra("student", student)
            setResult(RESULT_OK, intent)
            finish()
        }

        btnCancel.setOnClickListener {
            finish()
        }
    }
}